using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using NHibernate.Cfg;
using NHibernate;

using Advisor.Entities;
using System.Collections;
using NHibernate.Criterion;

namespace rm_Advisor
{

  public partial class Login : ComponentFactory.Krypton.Toolkit.KryptonForm
  {

    private Users m_Users;
    public Users users
    {
      get
      {
        return this.m_Users;
      }
      set
      {
        this.m_Users = value;
      }

    }
    public Login()
    {
      InitializeComponent();
    }

    private void btnLogar_Click(object sender, EventArgs e)
    {
      FilterCollection filters = new FilterCollection();
      filters.Add(Expression.Eq("Login", this.txtLogin.Text));
      filters.Add(Expression.Eq("Password", this.txtPassword.Text));
      EntitiesFC fc = new EntitiesFC(this.m_Users);
      Users user = fc.GetUser(filters);

      if (user != null)
      {
        this.users = user as Users;
        this.DialogResult = DialogResult.OK;

      }
      else
      {
        MessageBox.Show("Login ou senha incorreto!");
      }

    }

    private void txtExit_Click(object sender, EventArgs e)
    {
      this.DialogResult = DialogResult.Cancel;

    }

    private void txtPassword_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyData == Keys.Enter)
        {
            this.btnLogar_Click(sender,e);
        }
    }
  }
}